<?php
/*
	首页
*/

defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
set_html('header','common/header-cms');
$return['pcd']=$_SESSION['pcd']?:array();
$_SESSION['area_code']=$_RQ['area_code']?:$_SESSION['area_code'];
$return['area_code']=$_SESSION['area_code'];
$data=array(
				'aid'=>2,
				'content'=>'主播发《'.$order['fee'].'》元红包,大家快抢啊！',
				'username'=>'主播',
				'uid'=>$_SESSION['uid'],
				'uniacid'=>$_SESSION['uniacid'],
				'plugin_name'=>'jy_h5live',
				'status'=>1,
				'createtime'=>time(),
);
$socketdata=array('type'=>'sendred','data'=>$data);
//cfc('jinyun_socket')->send2room($socketdata,'room2');
if($_RQ['op']=='main'){
	$data=array(
		'aid'=>2,
		'content'=>'村上春树',
		'username'=>'测试测试',
		'uid'=>2,
		'uniacid'=>$_SESSION['uniacid'],
		'plugin_name'=>'jy_h5live',
		'status'=>1,
		'createtime'=>time(),
	);
	$socketdata=array('type'=>'msg','data'=>$data);
	//cfc('jinyun_socket')->send2room($socketdata,'room2');
	$return['indexpai']=array();	
	$setting = plugin('jy_weishop')->plugin_setting('setting');
	//公告列表
	$notice_list = pdo_fetchall('SELECT * FROM ' . tablename('jy_weishop_notice') . ' WHERE uniacid=:uniacid AND status=1  ORDER BY id DESC limit 4', array(':uniacid' => $_SESSION['uniacid']));
	if($notice_list){
		foreach($notice_list as &$notice){
			$notice['createtime']=date('Y-m-d h:i',$notice['createtime']);
		}
	}
	$return['list']=array();
	$return['params']['pid']=0;
	set_html('title',$return['pluginset']['title']?$return['pluginset']['title']:'直播系统');
	$return['sharedata']=array(
		'title'=>$return['pluginset']['share_title']?$return['pluginset']['share_title']:'在线互动直播系统',
		'desc'=>$return['pluginset']['share_desc']?$return['pluginset']['share_desc']:'在线互动直播系统，一个属于自己的直播间商城！',
		'link'=>custom_url('jy_h5live/index//fromuser='.$_SESSION['uid'],true),
		'imgUrl'=>ATTACHMENT_URL.$return['pluginset']['share_image']
	);
	$fenlei=pdo_getall('jy_weishop_live_group',array('uniacid'=>$_SESSION['uniacid'],'status'=>1));	
	$return['groups']=$fenlei?$fenlei:array();
	$return['params']['group_id']=0;
	$return['setting']=array();
	$return['indexpai'][]=array('name'=>'hdps');
	$return['setting']['hdps']=$return['pluginset']['hdps'];
	exi($return);
}
if($_RQ['op']=='getlist'){
	$fenlei=pdo_getall('jy_weishop_live_group',array('uniacid'=>$_SESSION['uniacid'],'status'=>1));	
	$params=array('uniacid'=>$_SESSION['uniacid'],'status'=>1);
	if($_RQ['title']){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	if($_RQ['order']){
		$return['params']['order']=trim($_RQ['order']);
		if($_RQ['order']=='ishot'){
			$params['ishot']=1;
		}elseif($_RQ['order']=='isrecommend'){
			$params['isrecommend']=1;
		}
	}
	$group_id=intval($_RQ['group_id']);
	$return['params']['group_id']=$group_id;
	if($group_id){
		$params['group_id']=$group_id;
	}
	$fields=array('id','title','group_id','image','createtime','looks','livetime','mid','isrecommend','ishot','living');
	$orderby=array();
	$_RQ['page'] = $_RQ['page'] ? $_RQ['page'] : 1;
	$pindex = max(1, intval($_RQ['page']));
	if(intval($_RQ['num'])){
		$psize = intval($_RQ['num']);
	}else{
		$psize = 10;
	}
	$total='';
	$list=pdo_getslice('jy_weishop_live_room',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['image'] = $item['image'] ? tomedia($item['image']) : tomedia('../core/resource/images/nopic.jpg');
			$item['createtime']=date('Y/m/d H:i:s',$item['createtime']);
			$item['livetime']=date('Y/m/d H:i:s',$item['livetime']);
			$item['grouptitle']=$fenlei[$item['group_id']]['title'];
			$item['member']=model('core/member')->detail($item['mid'],array('credit1','credit2','mobile','avatar','nickname'));
		}
	}
	$return['fenleiname']=$fenlei[$group_id]['title'];
	$return['groups']=$fenlei?$fenlei:array();
	$return['list']=$list?$list:array();
	exi($return);
}
?>